package com.neusoft.neumooc.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.neusoft.core.common.conf.Params;
import com.neusoft.core.util.IDUtil;
import com.neusoft.neumooc.VO.UserVO;
import com.neusoft.neumooc.service.UserService;

@Controller
@RequestMapping(value = "/register")
public class RegisterController {
	@Autowired
	UserService userService;

	@RequestMapping(value = "/userRegister")
	@ResponseBody
	public Map<String, Object> getUserByName(HttpServletRequest request,
			HttpServletResponse response, String userName, UserVO userVO) {
		Map<String, Object> retMap = new HashMap<String, Object>();
		Map<String, Object> map = userService.getUserByName(userName);
		if (map != null) {
			retMap.put(Params.RET_CODE, Params.RET_CODE_ERROR);
			retMap.put(Params.RET_OBJ, "用户名存在");
		} else {
			try {
				String id = IDUtil.getID();
				String uId = IDUtil.getID();
				userVO.setId(id);
				userVO.setuId(uId);
				userService.register(userVO);
				retMap.put(Params.RET_CODE, Params.RET_CODE_SUCCESS);
				retMap.put(Params.RET_OBJ, "注册成功");
			} catch (Exception e) {
				retMap.put(Params.RET_OBJ, "数据异常");
			}
		}
		return retMap;
	}
}
